import { syncSetTimeout, sendMessage, getMessage } from "../../global/tools.js";
import Call from "./Call.js";
import PhoneBarHandler from "./PhoneBarHandler.js";

export default class WebController {
    static count = 0;
    constructor() {
        WebController.count++;
        if (WebController.count >= 2) {
            alert("collectionPlugin: \nError: WebController.count >= 2，即将刷新页面。");
            location.reload(true);
        } 
        console.error("[collectionPlugin]", "WebController.js is running.");
        this.document = () => document;
        // 监听事件
        {
            this.eventListenersFn = {
                // click: {
                //     title: "click",
                //     fn: async e => {
                //     },
                //     capture: true
                // }
            };
            // 开始监听相关事件
            for (const key in this.eventListenersFn) {
                this.document().addEventListener(this.eventListenersFn[key].title, this.eventListenersFn[key].fn, this.eventListenersFn[key].capture ? true : false);
            }
        }
        this.init();
    }
    init() {
        let modulesConfig = {
            "call": Call,
            "phoneBarHandler": PhoneBarHandler,
        };

        Object.keys(modulesConfig).forEach(item => {
            if (modulesConfig[item]) {
                this[item] = new modulesConfig[item](this);
            }
        });
    }
}